#ifndef _SHADOW_FILE_SYSTEM_CLIENT_H_
#define _SHADOW_FILE_SYSTEM_CLIENT_H_

#include <log4cxx/logger.h>

#include "CnfSvrClient.h"
#include "NameSvrClient.h"
#include "DataSvrClient.h"
#include "MetadataSvrClient.h"

using namespace log4cxx;


class SFSClient {
	public:
		int init(const char * log_conf_file, const char * cs_ip, unsigned short cs_port, int cs_conn_pool_size, \
			int cs_socket_conn_timeout, int cs_socket_send_timeout, int cs_socket_recv_timeout, \
			int cs_socket_max_response_size);
		int query_is_file_exist(const char * file_path, int & exist_flag);
		int create_file(const char * file_path);
		int read_file(const char * file_path, char * buf, const int64_t begin_pos, const int len);
		int write_file(const char * file_path, const char * buf, const int len, int64_t begin_pos, int write_mode);
		int delete_file(const char * file_path);
		int query_is_dir_exist(const char * dir_path, int & exist_flag);
		int create_dir(const char * dir_path);
		int delete_dir(const char * dir_path);
		int64_t get_file_size(const char * file_path);
		int read_dir(const char * dir_path, list<string> & entries);
		int get_file_stat(const char * file_path, struct stat & s);
		int truncate(const char * file_path, int64_t size);
	protected:
		int init_logger(const char * log_conf_file);
		int assign_a_ds_4_read(MD_FILE_INFO info);
		bool is_crcs_equal(vector<uint32_t> crcs1, vector<uint32_t> crcs2);
		int alloc_a_ds_4_write(MD_FILE_INFO info);
		int calc_updated_client_crcs(int mds_id, MD_FILE_INFO info, int32_t dir_id, int64_t file_id, const char * buf, \
						int len, int64_t begin_pos, int write_mode, vector<uint32_t> & new_client_crcs);		int calc_updated_client_crcs_4_truncate(int mds_id, MD_FILE_INFO info, int32_t dir_id, int64_t file_id, int64_t size, \
						vector<uint32_t> & new_client_crcs);
	
		int64_t calc_file_size(MD_FILE_INFO  mdfi);
	private:
		CnfSvrClient _csc;
		NameSvrClientManager _nscm;
		MetadataSvrClientGroup _mdscg;
		DataSvrClientGroup _dscg;
		static LoggerPtr _logger;
		string _log_conf_file;
};

#endif
